package com.lwl.leetcode;

import org.junit.Test;

/**
 * @author lwl
 * @Description TODO
 * @date 2023/8/2 8:42
 */
public class Code55CanJump {

    public boolean canJump(int[] nums) {
        if (nums == null || nums.length == 0) {
            return false;
        }
        int maxRight = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (maxRight < i) {
                return false;
            }
            maxRight = Math.max(maxRight, i + nums[i]);
        }
        return true;
    }

    @Test
    public void test() {
        System.out.println(canJump(new int[]{2, 3, 1, 1, 4}));
        System.out.println(canJump(new int[]{3, 2, 1, 0, 4}));
    }

}
